<template>
  <div class="home">
    <search/>
    <choose :list="choiceList" />
    <company :list="companyList" />
    <job />
  </div>
</template>

<script>
import {homePage} from '@/api/home';
import {getChoice} from '@/api/choice';
import {setUserInfo} from '@/utils/cookie';
import search from '@/components/search/search'
import choose from '@/components/choose/choose'
import company from '@/components/company/company'
import job from '@/components/job/job'

export default {
  name: 'home',
  components: {
    search,
    choose,
    company,
    job,
  },
  data () {
    return {
      title: '首页',
      choiceList: [],
      companyList: [],
      hotjobList: []
    }
  },
  computed: {},
  created () {
    this.fetchData();
    this.getHomePage();
  },
  mounted () {

  },
  activated () {

  },
  methods: {
    getHomePage () {
      homePage({}).then(res => {
        if (res.code === 200) {
          this.info = res.data;
          res.data.company && (this.companyList = res.data.company);
          // 获取最新用户信息
          if (res.data.user_info) {
            this.$store.dispatch('userInfo', res.data.user_info);
            setUserInfo(JSON.stringify(res.data.user_info), 30)
          }
        } else if (res.code === 1008) {
          console.log('请登录')
        } else {
          this.$alertErr(res.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$alertErr(err)
      })
    },
    fetchData () {
      getChoice({}).then(res => {
        if (res.code === 200) {
          this.choiceList = [...res.data.online, ...res.data.offline];
        } else {
          this.$alertErr(res.msg || '网络错误！')
        }
      }).catch(err => {
        console.log(err)
        this.$alertErr(err || '网络错误！')
      })
    },
    jumpTo (path, query = {}) {
      if (!path) return
      let timers = setTimeout(() => {
        this.$router.push({
          path: path,
          query: query,
        })
        clearTimeout(timers)
        timers = null
      }, 300)
    },
  },
}
</script>
<style lang="stylus" scoped>
.home {

}
</style>


